/*
Project:				Perry Intergenerational
Author:					Victor Ronda
Original Date:			January 21, 2022
*/



*-------------------------------------------*
*  Computing the Table A.9 in the Appendix  *
*-------------------------------------------*


*---------------------------- Loading Results -----------------------------*

use $emp/Results/estimates_nonbio_children.dta, clear
append using $emp/Results/asym_pval_nonbio_children.dta
append using $emp/Results/perm_pval_nonbio_children.dta
append using $emp/Results/boot_pval_nonbio_children.dta

local l_vname1_nspecialedu00 "Fraction Never in Special Education"
local l_vname1_nsusp00 "Fraction Never Suspended from School"
local l_vname1_narrested00 "Fraction Never Arrested"
local l_vname1_naddicted00 "Fraction Never Addicted"
local l_vname1_ghealth200 "Fraction in Good Health"
local l_vname1_rhs18 "High School Graduation Rate"
local l_vname1_ntpreg19 "Pregnancy Rate (reversed scale)"
local l_vname1_scol21 "Post-Secondary Education Rate"
local l_vname1_ccol23 "College Graduation Rate"
local l_vname1_yedu23 "Average Years of Education"
local l_vname1_femp23 "Employment Rate"
local l_vname1_cmarried23 "Fraction Currently Married"
local l_vname1_ndivor23 "Fraction Never Divorced"

global vlist   ghealth200 nspecialedu00 nsusp00 narrested00 ntpreg19 femp23 yedu23 ndivor23



* first row
sum ghealth200_aipwd_22 if _n==1
sum ghealth200_aipwse_22 if _n==4
sum ghealth200_aipwd_22 if _n==2
sum ghealth200_aipwd_22 if _n==3
sum ghealth200_aipwd_22 if _n==4
sum ghealth200_aipwt_22 if _n==4

* second row
sum ghealth200_udimd_22 if _n==1
sum ghealth200_udimse_22 if _n==4
sum ghealth200_colsd_22 if _n==1
sum ghealth200_colsse_22 if _n==4
sum ghealth200_lblld_22 if _n==4
sum ghealth200_lbuld_22 if _n==4


file open latex_table using "$emp/Tables/tab_main_nonbio_jan2022_1.tex", write replace
foreach dvar in $vlist {

*** First Line ***

* Name
local `dvar'_line1 "`l_vname1_`dvar'' "

* Estimate
local e_estm = `dvar'_aipwd_22[1]
local estm "e_estm"
local `dvar'_line1 "``dvar'_line1' & $ `: di %5.3f ``estm'' ' $"

* Bootstrap Standard Error
local e_estm = `dvar'_aipwse_22[4]
local estm "e_estm"
local `dvar'_line1 "``dvar'_line1' & ($ `: di %5.3f ``estm'' ' $)"

* Analytic P-val
local e_estm = `dvar'_aipwd_22[2]
local estm "e_estm"
local `dvar'_line1 "``dvar'_line1' & [$ `: di %5.3f ``estm'' ' $]"

* Permutation P-val
local e_estm = `dvar'_aipwd_22[3]
local estm "e_estm"
local `dvar'_line1 "``dvar'_line1' & [$ `: di %5.3f ``estm'' ' $]"

* Bootstrap P-val
local e_estm = `dvar'_aipwd_22[4]
local estm "e_estm"
local `dvar'_line1 "``dvar'_line1' & [$ `: di %5.3f ``estm'' ' $]"

* Bootstrap-t P-val
local e_estm = `dvar'_aipwt_22[4]
local estm "e_estm"
local `dvar'_line1 "``dvar'_line1' & [$ `: di %5.3f ``estm'' ' $]"

}
foreach dvar in $vlist {
	file write latex_table "``dvar'_line1' \\" _n
}
file close latex_table


file open latex_table using "$emp/Tables/tab_main_nonbio_jan2022_2.tex", write replace
foreach dvar in $vlist {

*** Second Line ***
* Name
local `dvar'_line2 "`l_vname1_`dvar'' "

* Mean Differences
local e_estm = `dvar'_udimd_22[1]
local estm "e_estm"
local `dvar'_line2 "``dvar'_line2' & $ `: di %5.3f ``estm'' ' $"

* Mean Differences SE
local e_estm = `dvar'_udimse_22[4]
local estm "e_estm"
local `dvar'_line2 "``dvar'_line2' & ($ `: di %5.3f ``estm'' ' $)"

* OLS
local e_estm = `dvar'_colsd_22[1]
local estm "e_estm"
local `dvar'_line2 "``dvar'_line2' & $ `: di %5.3f ``estm'' ' $"

* OLS SE
local e_estm = `dvar'_colsse_22[4]
local estm "e_estm"
local `dvar'_line2 "``dvar'_line2' & ($ `: di %5.3f ``estm'' ' $)"

* Lee bounds - lower
local e_estm = `dvar'_lblld_22[1]
local estm "e_estm"
local `dvar'_line2 "``dvar'_line2' & $ `: di %5.3f ``estm'' ' $"

* Lee bounds - upper
local e_estm = `dvar'_lbuld_22[1]
local estm "e_estm"
local `dvar'_line2 "``dvar'_line2' & $ `: di %5.3f ``estm'' ' $"
}

foreach dvar in $vlist {
	file write latex_table "``dvar'_line2' \\" _n
}
file close latex_table

